import { createSelector } from '@ngrx/store';

import { getResourceTreeState } from './resource-tree.selector';
import { ResourceTreeState, PublicState } from '../reducers';

import { TreeItem, TreeviewItem } from '../../components';

const getPublicState = createSelector(getResourceTreeState, (state: ResourceTreeState) => state.public);
const getAllPublics = createSelector(getPublicState, (state: PublicState) => state.data);
const getAllPublicsToTreeview = createSelector(getAllPublics, (data: TreeItem[]) => {
    return data.map((treeItem: TreeItem) => new TreeviewItem(treeItem));
});
const getPublicLoaded = createSelector(getPublicState, (state: PublicState) => state.loaded);
const getPublicLoading = createSelector(getPublicState, (state: PublicState) => state.loading);

export const publicSelectors = {
    getPublicState,
    getAllPublics,
    getAllPublicsToTreeview,
    getPublicLoaded,
    getPublicLoading
};